const app = getApp();
var api = require('../../api.js');
let WxParse = require('../../wxParse/wxParse.js');
var mta = require('../../mta_analysis.js');

Page({
  data: {
    list: 'XXX',
    article: '111',
  },
  onLoad: function (options) {
    console.log(options)
    var page = this;
    let list = JSON.parse(options.str);
    console.log(list);
    wx.setNavigationBarTitle({
      title: list.name
    })
    page.setData({
      id:list.id
    });
    page.getDetail();

    mta.Page.init();
  },
  onReady: function () {
  
  },
  onShow: function () {
  
  },
  onHide: function () {
    var url = app.getcurrentPageStr();
    wx.setStorageSync("from_url", url);
  },
  onUnload: function () {
  
  },
  onPullDownRefresh: function () {
  
  },
  onReachBottom: function () {
  
  },
  onShareAppMessage: function () {
    
    var url = app.getcurrentPageStr();
    var user_id = wx.getStorageSync('user_id');
    return {
      path: url + "&user_id=" + user_id,
      title: '得道1314'
    };

  },
  //获取详情
  getDetail: function () {

    var that = this;

    var access_token = wx.getStorageSync('access_token');
    console.log(that.data.id);
    wx.request({
      url: api.index.lessonDetail,
      method: "get",
      header: {
        'content-type': 'application/x-www-form-urlencoded'
      },
      data: {
        access_token: access_token,
        lesson_id: that.data.id,
      },

      success: function (res) {
        console.log(res);

        var article = res.data.data.content;
        console.log(article);

        if (res.data.code == 0) {
          var temp = WxParse.wxParse('article1', 'html', article , that, 5);
          // that.setData({
          //   article: temp,
          // })
        }

      }
    });
  },
  back: function (e) {
    wx.navigateBack({
      delta: 1
    })
  },
})